package com.guavestudios.fnfo.plugins {
	import com.adobe.images.JPGEncoder;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestHeader;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.utils.ByteArray;
	import ru.inspirit.net.MultipartURLLoader;
	/**
	 * ...
	 * @author maze
	 */
	public class FnfoScreenshot extends BasicFnfoPlugin{
		
		protected var screenshot:BitmapData;
		
		public function FnfoScreenshot() {
			_pluginId = "FnfoScreenshot";
		}
		
		override protected function fnfo_show(e:Event):void {
			super.fnfo_show(e);
			var bmp:BitmapData = new BitmapData(_fnfo.container.stage.stageWidth, _fnfo.container.stage.stageHeight);
			bmp.draw(_fnfo.container);
			screenshot = bmp;
			
			//sendScreenshot();
		}
		
		public function sendScreenshot():void {
			var enc:JPGEncoder = new JPGEncoder(80);
			var data:ByteArray = enc.encode(screenshot);
			
			var jpgURLRequest:URLRequest = new URLRequest("http://192.168.1.25/maze/index.php");
			//jpgURLRequest.requestHeaders.push(header);
			jpgURLRequest.method = URLRequestMethod.POST;
			
			var urlLoader:MultipartURLLoader = new MultipartURLLoader();
			urlLoader.addVariable("testpost","testseaafdsafsdf");
			urlLoader.addFile(data, "screenshot");
			urlLoader.load(jpgURLRequest.url);
		}
		
		
	}

}